package domain

import (
	"go_web/src/domain"
	"go_web/src/util"
	"strconv"
	"time"
)

type OrderBo struct {
	UserId    uint    `json:"userId" form:"userId" gorm:"column:user_id" binding:""`
	ProductId uint    `json:"productId" form:"productId" gorm:"column:product_id" binding:""`
	OrderNum  string  `json:"orderNum" form:"orderNum" gorm:"column:order_num" binding:"required,min=12,max=50"`
	Num       int16   `json:"num,omitempty" form:"num" gorm:"column:num" binding:"required,min=12,max=50"`
	Price     float64 `json:"mobile,omitempty" form:"mobile" gorm:"column:phone" binding:"required,phone"`
}

func (u OrderBo) getName() domain.Order {
	order := domain.Order{
		UserId:     u.UserId,
		ProductId:  u.ProductId,
		OrderNum:   util.NewOrderGenerator(strconv.Itoa(int(u.UserId)), 1),
		Num:        u.Num,
		Price:      u.Price,
		CreateTime: time.Now(),
		UpdateTime: time.Now(),
	}
	return order
}
